package com.macro.mall.controller.commission;

import com.github.pagehelper.Page;
import com.macro.mall.commission.domain.UserBalanceChange;
import com.macro.mall.commission.entity.UserBalanceChangeEntity;
import com.macro.mall.commission.service.UserBalanceChangeService;
import com.macro.mall.commission.service.bo.PagedQueryUserBalanceChangeInput;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.dto.commission.PagedQueryUserBalanceChangeReqDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 用户账户余额变更记录控制器
 *
 * @author xuyanjun
 * @date 2020-01-04
 */
@Api(tags = "会员账户余额变更记录")
@Slf4j(topic = "UserBalanceChangeController")
@RestController
@RequestMapping("/userBalanceChange")
public class UserBalanceChangeController {

    @Autowired
    private UserBalanceChangeService userBalanceChangeService;

    /**
     * 分页查询用户账户余额变更记录
     *
     * @return 分页后的用户账户余额变更记录
     */
    @ApiOperation("分页查询用户账户余额变更记录")
    @PostMapping("pagedQuery")
    public CommonPage<UserBalanceChange> pagedQuery(@RequestBody PagedQueryUserBalanceChangeReqDto reqDto) {
        PagedQueryUserBalanceChangeInput pagedQueryUserBalanceChangeInput = new PagedQueryUserBalanceChangeInput();
        pagedQueryUserBalanceChangeInput
                .setMemberId(reqDto.getMemberId())
                .setPageIndex(reqDto.getPageIndex())
                .setPageSize(reqDto.getPageSize());

        Page<UserBalanceChangeEntity> userBalanceChangeEntities = userBalanceChangeService.pagedQuery(pagedQueryUserBalanceChangeInput);
        List<UserBalanceChange> userBalanceChanges = userBalanceChangeService.entityToDomain(userBalanceChangeEntities);

        return CommonPage.restPage(userBalanceChanges);
    }
}

